package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     * @return
     */
    @Override
    public List<NursingLevelVo> listAll() {
        List<NursingLevelVo> list=nursingLevelMapper.listAll();

        return list;
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     */
    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        //1.
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        //2.
        bean.setCreateTime(LocalDateTime.now());
        bean.setUpdateTime(LocalDateTime.now());
        bean.setStatus(1);
        //3.
        nursingLevelMapper.insert(bean);
    }

    /**
     * 分页查询护理等级
     */
    @Override
    public PageResponse<NursingLevelVo> listByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //1.
        PageHelper.startPage(pageNum,pageSize);
        //2.
        Page<NursingLevelVo> page=nursingLevelMapper.listByPage(name,status);

        return PageResponse.of(page, NursingLevelVo.class);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo searchById(Integer id) {
        NursingLevelVo result=nursingLevelMapper.searchById(id);

        return result;
    }

    /**
     * 修改项目等级
     * @param nursingLevelDto
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        //1.
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        //2.
        bean.setUpdateTime(LocalDateTime.now());
        //3.
        nursingLevelMapper.update(bean);
    }

    /**
     *删除项目等级
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        nursingLevelMapper.deleteById(id);
    }

    /**
     * 项目等级的启用和禁用
     * @param id
     * @param status
     */
    @Override
    public void idAndStatus(Integer id, Integer status) {
        nursingLevelMapper.idAndStatus(id,status);
    }
}
